API Tutorials

You can use these to navigate
[General][What you'll need]

[Finding Windows][Sending Messages][Common Messages








This page will try to make learning API a little easier for you. The whole idea of API (Application Programming Interface) is very simple. Basically it's sending messages from one program to another. Using declarations of functions that are in DLL's (Dynamic Link Library), we send messages through numbers, text and also commands such as to close, resize, and etc.. But the part of API that deals with sending the message isn't the biggest part, which is the part of narrowing class names down.
What you will need


What you'll need for this primer is declarations, which you can find in my Bas file (or any for that matter). You'll also need an API Spy, if i uploaded it to the files section yet you can get it off of there. Its called APISpy, it's very basic, simply gives the handels and class names and such. Just so you know an ApiSpy type of program just shows you the names and is not meant to "Generate" codes like some programmers are making. I hate the whole idea of that because people now think that it was an ApiSpy does and that they're really writing there own codes. well...you're not. And finally, depending on how you want to program your Bas file you'll either need a function called FindChildByClass which is a generic function most programmers use, or you can use FindWindowEx which is just as easy (dont let people who use this tell you they're "leeter" than you because they use it), it's the same type, they do the same job. But i like using FindChildByClass. I will admit that i use FindWindowEx for certain things i feel FindChildByClass isn't too good for.
Finding Windows


Take a look at this image of my computer screen.


What i wrote on the screen picture is the class names. With these class names i gave you (or you can find with the ApiSpy), you should be able to find an icon on the Aol Toolbar. How? here's how:

Aol% = FindWindow("AOL Frame25",VBNullString)'This will find the main aol window
Tool% = FindChildByClass(Aol%,"Aol Toolbar")'This tells VB to look inside the Aol handel for a class name of Aol Toolbar.
Toolb% = FindChildByClass(Tool%,"_AOL_Toolbar")'Tells vb to look for _AOL_Toolbar class name in a window.
Icona% = FindChildByClass(Toolb%,"_AOL_Icon")'Tells VB to look for _AOL_Icon in Toolb% Handel.

Now that you found the Icon how are we going to click it?
Sending the message
Sending messages is the easy part. Look in your Declarations and you'll see one for a function called SendMessage. we use this to do the job. After you've found the handel to the Icon, which in my example is in Icona%, all you have to do is use SendMessage along with the constants WM_LButtonDown and WM_LButtonUp. Those are very self explanatory, if not then you should see they stand for Left Button(Mouse) Down and for Up. so..Icona% is the icon and we want to click it easy, the line looks like this
ClickIt = SendMessage(Icona%,WM_LButtondown,0,0&)
ClickIt = SendMessage(Icona%,WM_LButtonUp,0,0&)
Ah Ha, it's clicked!!


Common Messages
Here's a list of some common window messages and what you should use them on:

WM_CLOSE
all i hear all day is "how do i close an IM, chat, etc" well this is how:
Narrow a search down to the main windows class name/handel, then use this:
'now ya see it Call SendMessage(Window%,WM_CLOSE,0,0&)
'now ya don't
SW CONSTANTS
to use the SW constants you have to have the declaration of the ShowWindow function
all the const and decs for this page are in the declaration bas on my files page.

SW_MINIMIZE, SW_MAXIMIZE, SW_SHOW, SW_HIDE
The syntax for all of these are:
Call ShowWindow(window%,SW_MINIMIZE) Call ShowWindow(window%,SW_HIDE) and etc..
LB_GETCOUNT
Used to get the number of items in a programs listbox
Num = SendMessage(ListBox%,LB_GETCOUNT,0,0&)
Now Num = the number